<?php
namespace app\mobile\controller;

use app\model\Record; 
use app\model\Theme; 
use app\model\Worker; 

class WSetxuni extends Base
{
    public function W_setxuni()
    {
global $_G, $_P;
$fans = $this->checkuser();
$themeid = intval($_P['themeid']);
if($themeid < 0){
	return_msg('管理后台地址不正确');
}
$system=$_G['system'];
$theme = Theme::getThemeById($themeid);
$config = 	Theme::getConfig($themeid);
if(empty($theme['id'])){
	return_msg('管理后台地址不正确');
}
$myworker = Worker::getThemeWorkerByOpenidNew($_G['openid'],$themeid);
if(!($system['ruanjian']!=3 || $config['showshop']==0 || ($system['ruanjian']==3 && $config['showshop']==$myworker['company']))){
	$myworker = "";
}
if (empty($myworker)) {
	return_msg('您不是员工,无权访问');
}
$msg = Worker::gethoutaistats();
if (!empty($msg)) {
	return_msg($msg);
}
$do = 'order';
$op = !empty($_P['op']) ? $_P['op'] : 'display';
$id = intval($_P['id']);

if ($op=='display') {

	if ($system['ruanjian']==0 && $system['softstyle']==5) {
		$total1 = Record::getNumByThemeId($themeid,$config['touxiang'],$config['showalldata']);
    	$tiaojian =" WHERE recordid=99999 ";
		$total = db_fetchcolumn('SELECT COUNT(*) FROM ' .tablename(t_shengshi)."  {$tiaojian}");
	    $totalsum = $total1  + $total;
	}elseif ($system['ruanjian']==3 && $system['softstyle']==2) {
		$total1 = Record::getNumByThemeId($themeid,$config['touxiang'],$config['showalldata']);
	    $totalsum = $total1 ;
	}else{
		$total1 = Record::getNumByThemeId($themeid,$config['touxiang'],$config['showalldata']);
	    $totalsum = $total1;

	}
	$scannum = Record::getscannumByThemeId($themeid,$config['showalldata']);

    // if ($system['softstyle']==7 || $system['ruanjian']==1){
    // 	$groupsnum =intval($theme['forward']);
    // }else{
    	$groupsnum = Record::getFansNumByThemeId($themeid,$config['showalldata']);
    // }

    $tuannum = Record::getGroupsNumByThemeId($themeid,$config['showalldata']);
	if($config['iscomm']==1 && $system['fenxiao07']==1){
		$commyaoyiyaofee = sprintf("%.2f",floatval(db_fetchcolumn ( 'SELECT sum(fee) FROM ' . tablename ( t_comm ) . "
		WHERE themeid ='{$themeid}' and type = 7 and status  = 1 " ))); 

		$commyaoyiyao = db_fetchcolumn ( 'SELECT count(*) FROM ' . tablename ( t_comm ) . "
		WHERE themeid ='{$themeid}' and type = 7 and status  = 1 " ); 
		$commyaoyiyao = $commyaoyiyao ;
		$commyaoyiyaofee = sprintf("%.2f",$commyaoyiyaofee );
	}

}elseif ($op=='save'){
	$config_old = $config;
	
	$config['touxiang'] = intval($_P['touxiang']);
	$config['fakejoin'] = intval($_P['fakejoin']);
	$config['faketuan'] = intval($_P['faketuan']);
	$config['fakescan'] = intval($_P['fakescan']);
	$config['comm7num'] = intval($_P['comm7num']);
	$config['comm7fee'] = intval($_P['comm7fee']);

	writelog($id,'手机编辑',$config_old,$config,$myworker['username']);
	Theme::setConfig($config,$themeid,$_G['mpid']);
    return_msg('更新成功','','success');
}
    
if($_G['companyname'] =='新飞驰软件'){
	$return_clicent = get_defined_vars();
return view('/fcworker/fc_setxuni' , $return_clicent);
}else{
	$return_clicent = get_defined_vars();
return view('/yxworker/w_setxuni' , $return_clicent);
}
}
}